{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d5060a5b-6b07-4c8d-8877-4b304ddc2e1a",
   "metadata": {},
   "source": [
    "# 循环神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "becbf9a5-727e-4207-91d9-c3fdc98f07bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "063866c2-8250-4b8b-b381-aa5fcb0b366e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tensor(shape=[3, 4], dtype=Float32, value=\n",
       "[[ 2.46109203e-01,  1.19690724e-01,  3.20074916e-01, -6.64670229e-01],\n",
       " [ 2.33567357e-01,  1.56107545e+00, -2.48459220e-01,  1.18619502e-02],\n",
       " [ 1.24855638e+00, -4.85641670e+00,  1.65460122e+00, -1.75428629e+00]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import mindspore\n",
    "import mindspore.ops as ops\n",
    "from d2l import mindspore as d2l\n",
    "\n",
    "X, W_xh = ops.normal((3, 1), d2l.tensor(0), d2l.tensor(1)), ops.normal((1, 4), d2l.tensor(0), d2l.tensor(1))\n",
    "H, W_hh = ops.normal((3, 4), d2l.tensor(0), d2l.tensor(1)), ops.normal((4, 4), d2l.tensor(0), d2l.tensor(1))\n",
    "d2l.matmul(X, W_xh) + d2l.matmul(H, W_hh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c94a55e7-4bb8-46b2-833c-5f0095bdeafb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tensor(shape=[3, 4], dtype=Float32, value=\n",
       "[[ 2.46109217e-01,  1.19690716e-01,  3.20074975e-01, -6.64670289e-01],\n",
       " [ 2.33567417e-01,  1.56107545e+00, -2.48459250e-01,  1.18619502e-02],\n",
       " [ 1.24855638e+00, -4.85641718e+00,  1.65460122e+00, -1.75428629e+00]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2l.matmul(d2l.concat((X, H), 1), d2l.concat((W_xh, W_hh), 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e42472f-1c1a-4601-89c1-a297dfcd2791",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ms_d2l",
   "language": "python",
   "name": "ms_d2l"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
